<?php
declare (strict_types=1);

namespace app\serviceapp;

use app\model\CategoryColorParam;
use app\traits\ServiceTrait;
use think\facade\Db;

/**
 * CategoryColorParam
 * Class CategoryColorParamService
 * @package app\service
 */
class CategoryColorParamService
{
    //模型，带命名空间
    public static $model = 'app\model\CategoryColorParam';
    //模型主键
    public static $pk = 'id';

    use ServiceTrait;

    /**
     * 根据labelId获取colorIds
     * @param $labelIds
     */
    public static function getColorIdByLabelIds($labelIds)
    {
        $table = CategoryColorParam::$_table;
        $colorIdData = Db::name($table)->where([['label_id', 'in', $labelIds]])->column('param_val');
        if (empty($colorIdData)) {
            return [];
        }
        $colorIds = implode(',', $colorIdData);
        $colorIdData = explode(',', $colorIds);
        $colorIdData = array_unique($colorIdData);
        return GoodsColorParamService::getGoodsIdByColorId($colorIdData);
    }
}
